API: gdk: Remove ability to render window contents
authorBenjamin Otte <otte@redhat.com>
Sun, 20 Nov 2016 10:47:32 +0000 (11:47 +0100)
committerBenjamin Otte <otte@redhat.com>
Sun, 20 Nov 2016 10:47:44 +0000 (11:47 +0100)
The functions gdk_pixbuf_get_from_window() and
gdk_cairo_set_source_window() are unreliable and depend on the windowing
system (they work great on X11 and Win32, less so on Quartz and Wayland).

With the switch to new drawing API and OpenGL, we can definitely no
longer support a generic way to snapshot windows.

People should either write windowsystem-specific code or draw their
widgets directly - like with gtk_widget_draw() - if they need to get a
rendering.

docs/reference/gdk/gdk4-sections.txt
gdk/gdkcairo.c
gdk/gdkcairo.h
gdk/gdkpixbuf-drawable.c
gdk/gdkpixbuf.h
gdk/gdkwindow.c

index d009b72a4a0d27785dfe78900715215307b75b01..48e7daf8eefacd2f5c9041333c110142e4f4c97a 100644 (file)
@@ -213,7 +213,6 @@ gdk_screen_get_type
 <SECTION>
 <TITLE>Pixbufs</TITLE>
 <FILE>pixbufs</FILE>
-gdk_pixbuf_get_from_window
 gdk_pixbuf_get_from_surface
 </SECTION>
 
@@ -538,7 +537,6 @@ gdk_cairo_get_clip_rectangle
 gdk_cairo_get_drawing_context
 gdk_cairo_set_source_rgba
 gdk_cairo_set_source_pixbuf
-gdk_cairo_set_source_window
 gdk_cairo_rectangle
 gdk_cairo_region
 gdk_cairo_region_create_from_surface
index 954e2c49dd52caaa6f88fa56438af2ab54beea0c..f1cc3c486a32c681a6d3430a0658cf61c0751b43 100644 (file)
@@ -323,40 +323,6 @@ gdk_cairo_set_source_pixbuf (cairo_t         *cr,
   cairo_surface_destroy (surface);
 }
 
-/**
- * gdk_cairo_set_source_window:
- * @cr: a cairo context
- * @window: a #GdkWindow
- * @x: X coordinate of location to place upper left corner of @window
- * @y: Y coordinate of location to place upper left corner of @window
- *
- * Sets the given window as the source pattern for @cr.
- *
- * The pattern has an extend mode of %CAIRO_EXTEND_NONE and is aligned
- * so that the origin of @window is @x, @y. The window contains all its
- * subwindows when rendering.
- *
- * Note that the contents of @window are undefined outside of the
- * visible part of @window, so use this function with care.
- *
- * Since: 2.24
- */
-void
-gdk_cairo_set_source_window (cairo_t   *cr,
-                             GdkWindow *window,
-                             gdouble    x,
-                             gdouble    y)
-{
-  cairo_surface_t *surface;
-
-  g_return_if_fail (cr != NULL);
-  g_return_if_fail (GDK_IS_WINDOW (window));
-
-  surface = _gdk_window_ref_cairo_surface (window);
-  cairo_set_source_surface (cr, surface, x, y);
-  cairo_surface_destroy (surface);
-}
-
 /*
  * _gdk_cairo_surface_extents:
  * @surface: surface to measure
index 1b3b961d3578ece86c48cafd498ac524c1a61c2a..52838423883cfe1cfb925f1b8c8c848400f5736f 100644 (file)
@@ -42,11 +42,6 @@ void       gdk_cairo_set_source_pixbuf  (cairo_t              *cr,
                                          const GdkPixbuf      *pixbuf,
                                          gdouble               pixbuf_x,
                                          gdouble               pixbuf_y);
-GDK_AVAILABLE_IN_ALL
-void       gdk_cairo_set_source_window  (cairo_t              *cr,
-                                         GdkWindow            *window,
-                                         gdouble               x,
-                                         gdouble               y);
 
 GDK_AVAILABLE_IN_ALL
 void       gdk_cairo_rectangle          (cairo_t              *cr,
index d2c142ae433796326ae70cb2f474aa7b33e26ea0..3c1e0f87970b765d8ec47e5a43dbc00a96b464cc 100644 (file)
  * #GdkWindows and cairo surfaces.
  */
 
-
-/**
- * gdk_pixbuf_get_from_window:
- * @window: Source window
- * @src_x: Source X coordinate within @window
- * @src_y: Source Y coordinate within @window
- * @width: Width in pixels of region to get
- * @height: Height in pixels of region to get
- *
- * Transfers image data from a #GdkWindow and converts it to an RGB(A)
- * representation inside a #GdkPixbuf. In other words, copies
- * image data from a server-side drawable to a client-side RGB(A) buffer.
- * This allows you to efficiently read individual pixels on the client side.
- *
- * This function will create an RGB pixbuf with 8 bits per channel with
- * the size specified by the @width and @height arguments scaled by the
- * scale factor of @window. The pixbuf will contain an alpha channel if
- * the @window contains one.
- *
- * If the window is off the screen, then there is no image data in the
- * obscured/offscreen regions to be placed in the pixbuf. The contents of
- * portions of the pixbuf corresponding to the offscreen region are undefined.
- *
- * If the window you’re obtaining data from is partially obscured by
- * other windows, then the contents of the pixbuf areas corresponding
- * to the obscured regions are undefined.
- *
- * If the window is not mapped (typically because it’s iconified/minimized
- * or not on the current workspace), then %NULL will be returned.
- *
- * If memory can’t be allocated for the return value, %NULL will be returned
- * instead.
- *
- * (In short, there are several ways this function can fail, and if it fails
- *  it returns %NULL; so check the return value.)
- *
- * Returns: (nullable) (transfer full): A newly-created pixbuf with a
- *     reference count of 1, or %NULL on error
- */
-GdkPixbuf *
-gdk_pixbuf_get_from_window (GdkWindow *src,
-                            gint       src_x,
-                            gint       src_y,
-                            gint       width,
-                            gint       height)
-{
-  cairo_surface_t *surface;
-  cairo_surface_t *copy;
-  cairo_t *cr;
-  GdkPixbuf *dest;
-  int scale;
-
-  g_return_val_if_fail (GDK_IS_WINDOW (src), NULL);
-  g_return_val_if_fail (gdk_window_is_viewable (src), NULL);
-
-  surface = _gdk_window_ref_cairo_surface (src);
-  scale = gdk_window_get_scale_factor (src);
-
-  /* We do not know what happened to this surface outside of GDK.
-   * Especially for foreign windows, they will have been modified
-   * by external applications.
-   * So be on the safe side and:
-   */
-  cairo_surface_mark_dirty (surface);
-
-  if (cairo_surface_get_content (surface) & CAIRO_CONTENT_ALPHA)
-    copy = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width * scale, height * scale);
-  else
-    copy = cairo_image_surface_create (CAIRO_FORMAT_RGB24, width * scale, height * scale);
-
-  cairo_surface_set_device_scale (copy, scale, scale);
-
-  cr = cairo_create (copy);
-  cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
-  cairo_set_source_surface (cr, surface, -src_x, -src_y);
-  cairo_paint (cr);
-  cairo_destroy (cr);
-
-  dest = gdk_pixbuf_get_from_surface (copy, 0, 0, width * scale, height * scale);
-
-  cairo_surface_destroy (copy);
-  cairo_surface_destroy (surface);
-
-  return dest;
-}
-
 static cairo_format_t
 gdk_cairo_format_for_content (cairo_content_t content)
 {
@@ -244,8 +158,7 @@ convert_no_alpha (guchar *dest_data,
  *
  * Transfers image data from a #cairo_surface_t and converts it to an RGB(A)
  * representation inside a #GdkPixbuf. This allows you to efficiently read
- * individual pixels from cairo surfaces. For #GdkWindows, use
- * gdk_pixbuf_get_from_window() instead.
+ * individual pixels from cairo surfaces.
  *
  * This function will create an RGB pixbuf with 8 bits per channel.
  * The pixbuf will contain an alpha channel if the @surface contains one.
index 4a96b1aee80d68499d05e1d6d07695e5571bc838..215c2773fb786edf41fc8084d3e3e3ac64f7c92c 100644 (file)
 
 G_BEGIN_DECLS
 
-GDK_AVAILABLE_IN_ALL
-GdkPixbuf *gdk_pixbuf_get_from_window  (GdkWindow       *window,
-                                        gint             src_x,
-                                        gint             src_y,
-                                        gint             width,
-                                        gint             height);
-
 GDK_AVAILABLE_IN_ALL
 GdkPixbuf *gdk_pixbuf_get_from_surface (cairo_surface_t *surface,
                                         gint             src_x,
index de2a8418211090f625d19a33c43cc99b7cef9d28..ee93ade486795b8d4e60362d1ee5ab63d8980fb8 100644 (file)
@@ -3175,62 +3175,6 @@ _gdk_window_ref_cairo_surface (GdkWindow *window)
     }
 }
 
-#if 0
-/**
- * gdk_cairo_create:
- * @window: a #GdkWindow
- * 
- * Creates a Cairo context for drawing to @window.
- *
- * Note that calling cairo_reset_clip() on the resulting #cairo_t will
- * produce undefined results, so avoid it at all costs.
- *
- * Typically, this function is used to draw on a #GdkWindow out of the paint
- * cycle of the toolkit; this should be avoided, as it breaks various assumptions
- * and optimizations.
- *
- * If you are drawing on a native #GdkWindow in response to a %GDK_EXPOSE event
- * you should use gdk_window_begin_draw_frame() and gdk_drawing_context_get_cairo_context()
- * instead. GTK will automatically do this for you when drawing a widget.
- *
- * Returns: A newly created Cairo context. Free with
- *  cairo_destroy() when you are done drawing.
- * 
- * Since: 2.8
- *
- * Deprecated: 3.22: Use gdk_window_begin_draw_frame() and
- *   gdk_drawing_context_get_cairo_context() instead
- **/
-cairo_t *
-gdk_cairo_create (GdkWindow *window)
-{
-  cairo_region_t *region;
-  cairo_surface_t *surface;
-  cairo_t *cr;
-
-  g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
-
-  surface = _gdk_window_ref_cairo_surface (window);
-
-  cr = cairo_create (surface);
-
-  region = gdk_window_get_current_paint_region (window);
-  gdk_cairo_region (cr, region);
-  cairo_region_destroy (region);
-  cairo_clip (cr);
-
-  /* Assign a drawing context, if one is set; if gdk_cairo_create()
-   * is called outside of a frame drawing then this is going to be
-   * NULL.
-   */
-  gdk_cairo_set_drawing_context (cr, window->drawing_context);
-
-  cairo_surface_destroy (surface);
-
-  return cr;
-}
-#endif
-
 /* Code for dirty-region queueing
  */
 static GSList *update_windows = NULL;